{template header}
<style type="text/css">
    .focusDiv {border-bottom: 2px solid #EEEEEE;}
    ul.link{margin: 10px auto;}
    ul.link li{list-style-type: none; float: left; margin: 2px 5px;background-color:#dbeaf9;padding:5px;cursor: pointer;border-radius: 4px;}
</style>
<script type="text/javascript">
    $(document).ready(function(){
        $("#link>li").click(function()
        {
            url = $(this).attr("data-url");
            $(this).parent().siblings("input").eq(0).val(url);
            alert('友情提示，不要忘记替换大括号中参数，并删除大括号');
        });
        $("button#addFocusImg").click(function(){
            var num = $("#totalFocusImg").val();
            num = parseInt(num) +1;
            $("#totalFocusImg").val(num);
            var newHtml = "<div class='control-group focusDiv' id='focusImg_"+num+"'><label class='control-label' for='inputTiltle'>Showtime图片（"+(num+1)+"）：</label><div class='controls'><div class='control-group'><div><span>图片：</span><input type='file' name='picture_"+num+"'></div></div></div><div class='control-group'><div class='controls'><span>跳转链接：</span><input type='text' name='link["+num+"]' placeholder='不需要跳转时请留空'> 排序：<input value='0' type='text' name='sort["+num+"]' placeholder='排序'><ul id='link' class='link'>{loop $urlArr $kk $v}<li data-url='{$v['link']}' onclick='showLinkUrl(this)'>{$v['name']}</li>{/loop}</ul></div></div><div class='controls'><button type='button' class='btn btn-danger' onclick='delFocusImg("+num+")'>删除本图片</button></div></div>";
            $("#focusImgList").append(newHtml);
        });
    });
    function showLinkUrl(frm){
        url = $(frm).attr("data-url");
        $(frm).parent().siblings("input").eq(0).val(url);
        alert('友情提示，不要忘记替换大括号中参数，并删除大括号');
    }
    function delFocusImg(key)
    {
        if(confirm("确认删除？") == true)
        {
            $("#focusImg_"+key).remove();
            var num = $("#totalFocusImg").val();
            num = parseInt(num);
            for(var i=num; i>=0; i--){
                if($("#focusImg_"+i).html() !== undefined){
                    $("#totalFocusImg").val(i);
                    return false;
                }
            }
        }
    }
</script>
<form class="form-horizontal" action="index.php?c=admin&a=editADPosition" method="post" enctype="multipart/form-data">
    <div id="focusImgList">
        {loop $focusImg $k $img}
        <div class="control-group focusDiv ptb-20" id="focusImg_{$k}">
            <label class="control-label" for="inputTiltle">Showtime图片（{eval echo $k+1}）：</label>
            <div class="controls">
                <div class="control-group">
                    <div class="">
                        <span>图片：</span>
                        {if $img['pictureUrl']}
                        <img width="50" src="{$img['pictureUrl']}" alt="图片">
                        {/if}
                        <input type="file" name="picture_{$k}">
                    </div>
                </div>
            </div>
            <div class="control-group">
                <div class="controls">
                    <span>跳转链接：</span>
                    <input type="text" name="link[{$k}]" placeholder="不需要跳转时请留空" value="{$img['linkUrl']}">
                     排序：<input type="text" name="sort[{$k}]" placeholder="排序" value="{$img['sort']}">
                    <ul id="link" class="link">
                        {loop $urlArr $kk $v}
                        <li data-url="{$v['link']}">{$v['name']}</li>
                        {/loop}
                    </ul>
                </div>
            </div>
            <div class="controls"><button type="button" class="btn btn-danger" onclick="delFocusImg('{$k}')">删除本图片</button></div>
        </div>
        {/loop}
    </div>
    <div class="control-group">
        <div class="controls">
            <input type="hidden" value="{$k}" id="totalFocusImg" name="num">
            <button type="button" class="btn btn-primary" id="addFocusImg">添加一个图片</button>
        </div>
    </div>
    <div class="control-group">
        <div class="controls">
            <button type="submit" class="btn">提交</button>
        </div>
    </div>
</form>
{template footer}
